%include "io.inc"

section .bss
    N equ 5
    arr resd N ; reserve N dword, total N*4 Bytes

section .text
global main
main:
    ;; 1.读取数组
    ;; ecx = N, ebx = 0
    mov ecx, N
    xor ebx, ebx
cycle_fill:
    ;; arr[ebx++] = read_num()
    GET_DEC 4, [arr + 4 * ebx]
    inc ebx
    ;; while (ecx-- > 0)
    loop cycle_fill

    ;; 2.累加
    ;; ecx = N, ebx = 0, eax = 0
    mov ecx, N
    xor ebx, ebx
    xor eax, eax
cycle_print:
    ;; eax = eax + arr[ebx++]
    add eax, [arr + 4 * ebx]
    inc ebx
    ;; while (ecx-- > 0)
    loop cycle_print

    ;; 3.除法，得到商和余数
    cdq
    idiv ebx ; eax = eax / ebx
    PRINT_DEC 4, eax ; division
    NEWLINE
    PRINT_DEC 4, edx ; mod

    xor eax, eax
    ret